package com.ex.mzwqz.activity;

import android.view.View;
import android.widget.AdapterView;

import com.ex.mzwqz.R;
import com.ex.mzwqz.adapter.NewsAdapter;
import com.ex.mzwqz.model.NewsEntity;
import com.ex.mzwqz.util.Constants;
import com.ex.mzwqz.util.UiManager;
import com.limxing.xlistview.view.XListView;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by xiaguoqiang on 16/10/20.
 */
public class NewsActivity extends BaseActivity implements XListView.IXListViewListener {

    private XListView lvNews;
    private NewsAdapter adtNews;
    private int infoType = 1;

    @Override
    protected int setContentViewResId() {
        return R.layout.activity_news;
    }

    @Override
    protected void initView() {
        infoType = getIntent().getIntExtra(Constants.REQUEST_TYPE_INFO_TYPE,1);
        switch (infoType){
            case 1:
                setTitle("新闻管理");
                break;
            case 2:
                setTitle("政策法规管理");
                break;
            case 3:
                setTitle("通知管理");
                break;
        }
        lvNews = (XListView) findViewById(R.id.lv_refresh_news);
        lvNews.setPullRefreshEnable(true);
        lvNews.setPullLoadEnable(true);
        lvNews.setXListViewListener(this);
        adtNews = new NewsAdapter(this, R.layout.item_news);
        lvNews.setAdapter(adtNews);
    }

    @Override
    protected void initData() {
//        for (int i = 0 ; i < 10 ; i ++) {
        switch (infoType){
            case 1:
                adtNews.addAll(getNew());
                break;
            case 2:
                adtNews.addAll(getPolicy());
                break;
            case 3:
                adtNews.addAll(getKnowdge());
                break;
            case 0:
                adtNews.addAll(getAll());
        }

//        }
    }

    public List<NewsEntity> getAll(){
        List<NewsEntity> list = new ArrayList<>();
//        for(int i=0; i<10; i++){
        list.add(new NewsEntity("556054","伊犁州召开现场会 推进化解钢铁行业过剩产能工作","新闻","2016-9-21",null));
        list.add(new NewsEntity("555815","张春贤：实施“一带一路”战略 新疆大有可为","政策法规","2016-6-6","http://zs.qinqinz.com/UploadFiles/editor/image/20150606/20150606152966986698.jpg"));
        list.add(new NewsEntity("555973","习近平在宁夏考察时强调 解放思想真抓实干奋力前进 确保与全国同步建成全面小康社会","新闻","2016-7-25","http://zs.qinqinz.com/UploadFiles/editor/image/20160725/2016072510080193193.jpg"));
        list.add(new NewsEntity("555857","新疆维吾尔自治区宗教事务条例","政策法规","2015-11-18",null));

//        }

        return list;
    }

    public List<NewsEntity> getPolicy(){
        List<NewsEntity> list = new ArrayList<>();
//        for(int i=0; i<10; i++){
        list.add(new NewsEntity("555857","新疆维吾尔自治区宗教事务条例","政策法规","2015-11-18",null));
        list.add(new NewsEntity("555815","张春贤：实施“一带一路”战略 新疆大有可为","政策法规","2016-6-6","http://zs.qinqinz.com/UploadFiles/editor/image/20150606/20150606152966986698.jpg"));

//        }

        return list;
    }

    public List<NewsEntity> getKnowdge(){
        List<NewsEntity> list = new ArrayList<>();
        return list;
    }

    public List<NewsEntity> getNew(){
        List<NewsEntity> list = new ArrayList<>();
//        for(int i=0; i<10; i++){
        list.add(new NewsEntity("556054","伊犁州召开现场会 推进化解钢铁行业过剩产能工作","新闻","2016-9-21",null));
        list.add(new NewsEntity("555973","习近平在宁夏考察时强调 解放思想真抓实干奋力前进 确保与全国同步建成全面小康社会","新闻","2016-7-25","http://zs.qinqinz.com/UploadFiles/editor/image/20160725/2016072510080193193.jpg"));

//        }

        return list;
    }
    @Override
    protected void initEvent() {
        lvNews.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                UiManager.toWebView(NewsActivity.this,"新闻详情",Constants.NEWS_BASE_URL + adtNews.getItem(i - 1).getId());
            }
        });
    }


    @Override
    public void onRefresh() {
        lvNews.stopRefresh();
    }

    @Override
    public void onLoadMore() {

        lvNews.stopLoadMore();
    }
}
